<?php

namespace app\controller\web;

use app\service\SendNoticeTableService;
use app\validate\PageValidate;
use app\validate\SendNoticeTableValidate;
use share\utils\Helper;

class SendNoticeTableController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new SendNoticeTableValidate();
    }

    /**
     * 新增系统通知
     */
    public function add_action(){
        $input = $this->check();
        $data = SendNoticeTableService::addNotice($input);
        return self::ok($data);
    }

    /**
     * 修改系统通知
     */
    public function edit_action(){
        $input = $this->check();
        $data = SendNoticeTableService::updateNotice($input);
        return self::ok($data);
    }

    /**
     * 删除系统通知
     */
    public function del_action(){
        $input = $this->check();
        $data = SendNoticeTableService::delNotice($input['id']);
        return self::ok($data);
    }

    /**
     * 列表 搜索
     */
    public function list_action(){
        $page = $this->check('pageInfo',null,(new PageValidate()));    
        $data = SendNoticeTableService::getListInfo([],$page);
        $data = Helper::arrayListReplaceKey($data,[
            'begin_time' => 'beginTime',
            'end_time' => 'endTime',
        ]);
        $total = SendNoticeTableService::getListCountInfo([]);
        return self::ok(self::formatPageData($page,$total,$data));
    }

}